<template>
	<view class="container">
		<u-cell-group>
			<u-cell v-for="item in orderlist" :key="item.id">
				<view slot="value">
					<view class="btn">
						<u-button type="error" :customStyle="btnStyle" size="mini" text="删除"
							@click="getdeldata(item,'error')">
						</u-button>
					</view>
				</view>
				<view slot="title" class="u-slot-title">
					<view style="padding-bottom: 5px;">
						用户名：{{item.business.nickname}}
					</view>
					<view style="padding-bottom: 5px;">
						课程名称：{{item.subject.title}}
					</view>
					<view style="padding-bottom: 8px;">
						价格：{{item.total}}
					</view>
				</view>
				<view slot="label">
					<view style="color:#909193">
						订单号：{{item.code}}
					</view>
				</view>
			</u-cell>
		</u-cell-group>
		<u-toast ref="uToast"></u-toast>
		<!-- 领取确认框 -->
		<u-modal :show="iSshow" :content='content' showCancelButton @cancel="iSshow = false" @confirm="confirm"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderlist: [],
				LoginUser: {},
				btnStyle: {
					width: '10%',
					display: "inline-block",
					marginRight: '5px',
					marginTop: '10px',
					lineHeight: '20px'
				},
				iSshow: false,
				content: '确认是否删除订单？',
				orderid: 0
			}
		},
		onReady() {
			this.$u.auth.check()
			this.LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {}
			this.getOrderData()
		},
		methods: {
			async getOrderData() {
				let result = await this.$u.api.admin.orderlist()
				if (result.code == 1) {
					this.orderlist = result.data
				}
			},
			getdeldata(val){
				this.iSshow = true;
				this.orderid = val.id
			},
			async confirm(){
				this.iSshow = false;
				let result = await this.$u.api.admin.orderdel({
					adminid: this.LoginUser.id,
					orderid: this.orderid
				})
				if (result.code == 1) {
					this.getOrderData()
					this.$refs.uToast.show({
						type: 'success',
						message: result.msg
					})
				} else {
					this.$refs.uToast.show({
						type: 'error',
						message: result.msg
					})
				}
			}
		}
	}
</script>

<style>
	.container {
		padding: 8px;
	}
</style>